package com.luo.chengrui.module.sa.enums;

import java.util.Arrays;
import java.util.Optional;

public enum OrgKindEnum {
    Root("root", "根节点"),
    Org("ogn", "机构"),
    Center("ctr", "中心"),
    Dept("dpt", "部门"),
    Position("pos", "岗位"),
    Psm("psm", "人员"),
    Folder("fld", "目录"),
    Project("prj", "项目组"),
    SaleTeam("stm", "销售团队"),
    Group("grp", "分组"),
    Function("function", "业务职能"),
    SystemGroup("system", "组织系统级分组"),
    //矩阵不属于组织机构类型，仅为使用方便
    OrgMatrix("orgMatrix", "组织矩阵"),
    bizMatrix("bizMatrix", "业务矩阵"),
    ;

    private String code;
    private String name;

    OrgKindEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static OrgKindEnum getByCode(String code) {
        Optional<OrgKindEnum> optional = Arrays.stream(OrgKindEnum.values()).filter(item -> item.code.equals(code)).findFirst();
        if (optional.isPresent()) {
            return optional.get();
        }

        throw new RuntimeException(String.format("编码%s存在枚举【OrgKindEnum】中不存在", code));
    }
}
